<template>
	<view>
		<view class="return" @click="toReturn()" style="box-shadow: 1rpx 2rpx 4rpx 2rpx gainsboro;">
			<u-icon name="arrow-left" size="20"></u-icon>
		</view>
		<view class="flex align" style="margin: 20rpx;">
			<u-search placeholder="券名搜索" :showAction="false" v-model="name" @change="onChange"></u-search>
			<u-search placeholder="券码搜索" :showAction="false" v-model="coupon_no" @change="onChange2"></u-search>
			<!-- 		<van-search model:value="{{ name }}" placeholder="券名搜索" use-action-slot bind:change="onChange"></van-search>
			<van-search model:value="{{ coupon_no }}" placeholder="券码搜索" use-action-slot
				bind:change="onChange2"></van-search> -->
		</view>
		<!-- 搜索 -->
		<view class="record">
			<view class="today-list">
				<view class="list flex between" v-for="(item,index) in list" :key="index">
					<view class="list-left flex">
						<view>
							<view style="font-size: 28rpx;margin-bottom: 10rpx;">券码：{{item.coupon_no}}</view>
							<view>券名：{{item.name}}</view>
							<view class="time">核销时间：{{item.use_time}}</view>
						</view>
					</view>
				</view>
				<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
				<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		tourVerificationList
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
				coupon_no: '',
				name: ''
			};
		},
		mounted() {
			this.getlist()
		},
		methods: {
			toReturn() {
				uni.navigateBack()
			},
			onChange2() {
				this.page = 0
				this.list = []
				this.getlist()
			},
			onChange() {
				this.page = 0
				this.list = []
				this.getlist()
			},
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
				} = that;
				let obj = {
					size: offset,
					page: page + 1,
					coupon_no: that.coupon_no,
					name: that.name
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await tourVerificationList(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
	}
</script>

<style lang="scss" scoped>
	page {
		padding-top: 80rpx;
		background: #F7F6F9;
	}

	.record {
		margin: 20rpx;
	}

	.search-btn {
		background: #C23015;
		color: white;
		padding: 0 20rpx;
	}

	.today-list {
		margin: 20rpx 0 35rpx;
	}

	.list-tit {
		position: relative;
		font-size: 26rpx;
		font-weight: bold;
	}

	.list-tit::before {
		content: '';
		position: absolute;
		background: linear-gradient(to right, #1E7EE9, #FFFFFF);
		width: 80rpx;
		height: 10rpx;
		bottom: 0;
		left: 0;
		z-index: -1;
	}

	.list {
		background: white;
		border-right: 20rpx;
		padding: 24rpx 36rpx;
		margin-top: 24rpx;
	}

	.list-left {
		font-size: 24rpx;
		color: #333333;
		font-weight: bold;
	}

	.list-left image {
		width: 72rpx;
		height: 72rpx;
		margin-right: 20rpx;
	}

	.time {
		color: gray;
		font-size: 22rpx;
		font-weight: normal;
		margin-top: 10rpx;
	}

	.list-ri {
		color: #FF2937;
		font-size: 26rpx;
		font-weight: bold;
	}

	.search-date {
		color: #00B2FF;
		font-size: 26rpx;
	}

	.search-date text {
		margin-right: 10rpx;
	}

	.search-right {
		background: #00B2FF;
		color: white;
		padding: 5rpx 10rpx;
		border-radius: 5rpx;
		width: fit-content;
		margin-left: auto;
		font-size: 28rpx;
	}
</style>